import {
  Entity,
  ManyToOne,
  JoinColumn,
  PrimaryGeneratedColumn,
  PrimaryColumn,
} from 'typeorm';
import { Role } from './role.entity';
import { Menu } from './menu.entity';
import * as crypto from 'crypto';
@Entity('role_menu')
export class RoleMenu {
  @PrimaryColumn({ length: 225 })
  id: string;

  @ManyToOne(() => Role, (role) => role.roleMenus, { onDelete: 'CASCADE' })
  @JoinColumn({ name: 'roleId' })
  roleId: Role;

  @ManyToOne(() => Menu, (menu) => menu.roleMenus, { onDelete: 'CASCADE' })
  @JoinColumn({ name: 'menuId' })
  menuId: Menu;

  constructor() {
    this.id = crypto.randomBytes(8).toString('hex'); // 生成一个8字节（16个十六进制字符）的随机字符串作为id
  }
}
